{% load static %}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="renderer" content="webkit">
<title>部门管理</title>
<link rel="stylesheet" href="{% static '/public/css/ui.css' %}">
<link rel="stylesheet" href="{% static '/public/admin/css/layout.css' %}">
<script src="{% static 'public/js/jquery.js' %}"></script>
<script src="{% static 'public/js/ui.js' %}"></script>
</head>

<body>

<div class="position">当前位置：网站管理 > <a href="{% url 'manager:part_index' %}">部门管理</a></div>
<div class="border">
    <!---->
    <a href="javascript:;" data-url="{% url 'manager:part_add' %}" class="add-iframe ui-btn ui-btn-info">添加部门</a>
    <form method="post" class="ui-form">
    <div class="ui-table-wrap">
    <table class="ui-table ui-table-border ui-table-hover ui-table-striped ui-mt ui-mb">
        <thead class="ui-thead-gray">
            <tr>
                <th width="80">排序</th>
                <th width="80">ID</th>
                <th>部门名称</th>
                <th width="350">操作</th>
            </tr>
        </thead>
        <tbody>
        {% for item in part_items %}
        <tr>
            <td><input type="hidden" name="mid[]" value="{{item.id}}"><input type="text" class="ui-form-ip" name="ordnum[]" id="ordnum_{{item.id}}" value="{{item.ordnum}}" data-rule="required;int;"></td>
            <td>{{item.id}}</td>
            <td class="ui-text-left">{{item.title}}</td>
            <td><a href="javascript:;" data-url="{% url 'manager:part_page' item.id %}" class="lever-iframe" data-title="页面权限"><span class="ui-icon-lock"></span> 页面权限</a>　<a href="javascript:;" data-url="{% url 'manager:part_cate' item.id %}" class="lever-iframe" data-title="栏目权限"><span class="ui-icon-lock"></span> 栏目权限</a>　<a href="javascript:;" data-url="{% url 'manager:part_edit' item.id %}" class="edit-iframe"><span class="ui-icon-edit"></span> 编辑</a>　<a href="javascript:;" class="del" data-url="{% url 'manager:part_del' item.id %}"><span class="ui-icon-delete"></span> 删除</a></td>
        </tr>
        {% endfor %}
        </tbody>
    </table>
    </div>
    {% if part_items %}
    {% csrf_token %}
    <button type="submit" class="ui-btn ui-btn-yellow">保存排序</button>
    {% endif %}
    </form>
    <!---->
</div>

<script>
$(function()
{
    const csrftoken = document.querySelector('[name=csrfmiddlewaretoken]').value;
    $(".add-iframe").click(function()
	{
		var url=$(this).attr("data-url");
		$.dialogbox(
		{
			'title':"添加部门",
			'text':url,
			'width':'600px',
			'height':'320px',
			'type':3,
			'oktheme':'ui-btn-info',
			'ok':function(e)
			{
				e.iframe().contents().find("#wmcms-submit").click();
			}
		});
	});
	$(".lever-iframe").click(function()
	{
		var url=$(this).attr("data-url");
		var title=$(this).attr("data-title");
		$.dialogbox(
		{
			'title':title,
			'text':url,
			'width':'600px',
			'height':'350px',
			'type':3,
			'oktheme':'ui-btn-info',
			'ok':function(e)
			{
				e.iframe().contents().find("#wmcms-submit").click();
			}
		});
	});
	$(".edit-iframe").click(function(){
		var url=$(this).attr("data-url");
		$.dialogbox(
		{
			'title':"编辑部门",
			'text':url,
			'width':'600px',
			'height':'320px',
			'type':3,
			'oktheme':'ui-btn-info',
			'ok':function(e)
			{
				e.iframe().contents().find("#wmcms-submit").click();
			}
		});
	});
	$(".ui-form").form(
	{
		type:2,
		result:function(form)
		{
			$.ajax(
			{
                type:'post',
                cache:false,
                dataType:'json',
                url:'{% url "manager:part_index" %}',
                data:$(form).serialize(),
                error:function(e){alert(e.responseText);},
                success:function(d)
                {
                    if(d.state=='success')
                    {
                        wmcms.success(d.msg);
                        setTimeout(function(){location.href='{% url "manager:part_index" %}';},1500);
                    }
                    else
                    {
                        wmcms.error(d.msg);
                    }
                }
            });
		}
	});
	
    $(".del").click(function()
	{
		var url=$(this).attr("data-url");
		$.dialog(
		{
			'title':"操作提示",
			'text':"确定要删除？不可恢复！",
			'oktheme':'ui-btn-info',
			'ok':function(e)
			{
				$.ajax(
				{
                    url:url,
					type:'post',
					dataType:'json',
                    headers: {'X-CSRFToken': csrftoken},
                    mode: 'same-origin',
					error:function(e){alert(e.responseText);},
                    success:function(d)
                    {
                        e.close();
                        if(d.state=='success')
                        {
                            wmcms.success(d.msg);
                            setTimeout(function(){location.href='{% url "manager:part_index" %}';},1000);
                        }
                        else
                        {
                            wmcms.error(d.msg);
                        }
                    }
                });
			}
		});
    });
})
</script>
</body>
</html>
